<template>
	<z-paging ref="paging" @query="ticketList">
		<template>
			<list :listinfo="listinfo" :current='current'></list>
			<view class="d-font-30 flex-space-between d-p-30">
				<view class="">
					购买数量
				</view>
				<view class="" v-if="current == '0'">
					<u-number-box :disabledInput="true" v-model="value" @change="valChange" :min="1" :max="5" color="#ffffff"
						bgColor="#35bcff" iconStyle="color: #fff"></u-number-box>
				</view>
				<view class="" v-else>
					<u-number-box :disabledInput="true" v-model="value" @change="valChange" :min="1" :max="1" color="#ffffff"
						bgColor="#35bcff" iconStyle="color: #fff"></u-number-box>
				</view>
			</view>

			<!-- 购物车结算 S -->
			<view class="goods-settle-accounts">
				<view class="left">
				</view>
				<view class="right">
					<block>
						<view class="goods-price-total">
							<text>合计: </text>
							<text>¥ {{total}}</text>
						</view>
						<view class="goods-count-btn" @click="$noMultipleClicks(orderclick)">
							提交订单
						</view>
					</block>
				</view>
			</view>
		</template>
		<customer-Kefu ></customer-Kefu>
	</z-paging>
</template>

<script>
	import {
		cardDetail,
		ticket,
		ordercreate
	} from '@/common/api';
	import list from '../components/list.vue';
	import customerKefu from '../../components/customerKefu/customerKefu.vue'
	export default {
		components: {
			list,
			customerKefu
		},
		data() {
			return {
				noClick: true,
				listinfo: {
					name: '内馆游泳门票',
					venues: '海湾内馆'
				},
				value: 0,
				current: '',
				badvalue: 2,
				type: "warning",
				total: 0,
				id:'',
				money:'',
				cardType:'',
				listinfo:{}
			};
		},
		onLoad(e) {
			this.id = e.id
			this.cardType = e.cardType
			this.current = e.current
			this.value = e.value
			this.ticketList()
		},
		methods: {
			//订单创建
			orderclick(){
				ordercreate({
						venue_id: uni.getStorageSync('venue_id'),
						card_id:this.id,
						card_type:this.cardType,
						platform:'H5',
						paytype:'微信',
					})
					.then(res => {
						console.log(res, '9966')
						
						let paymentData = res
						var jweixin = require('jweixin-module');
						jweixin.config({
							debug: false,
							appId: paymentData.appId, //必填
							jsApiList: ['chooseWXPay']
						});
						jweixin.ready(function() {
							jweixin.chooseWXPay({
								package: paymentData.package, 
								timestamp: paymentData.timeStamp, //必须小写
								nonceStr:paymentData.nonceStr,  
								signType: paymentData.signType, 
								paySign: paymentData.paySign, 
								success: function(res) {
									// 支付成功后的回调函数
									uni.showToast({
										icon: 'none',
										title: '支付成功',
									});
									setTimeout(()=>{
										uni.switchTab({
											url: '/pages/mine/mine'
										})
									},1000) 
								},
								cancel: function(r) {},
								fail: function(res) {
									console.log('payfail')
								}
							});
						});
						jweixin.error(function(res) {
							uni.showToast({
								icon: 'none',
								title: '支付失败了',
							});
						});
					})
			},
			// 金额计算保留两位小数
			amount(value) {
				return parseFloat(value).toFixed(2);
			},
			ticketList() {
				cardDetail({
						venue_id: uni.getStorageSync('venue_id'),
						cardId:this.id,
						cardType:this.cardType
					})
					.then(res => {
						this.total = res.saleprice
						this.listinfo = res
					})
			},
			shoppingclick() {
				// uni.$u.route({
				// 	url: '/pageA/shopping_cart/shopping_cart',
				// 	params: {}
				// });
			},
			valChange(e) {
				console.log('当前值为: ' + e.value)
				if (e.value == 5) {
					uni.$u.toast('单次购买不能大于五张，如有需要请至前台购买');
				}
				// this.total += e.value * this.money;
			},

			// cardDetail(id) {
			// 	uni.$u.route({
			// 		url: '/pages/home/cardDetail',
			// 		params: {
			// 			id
			// 		}
			// 	});
			// }
		}
	};
</script>

<style lang="scss" scoped>
	.d-list-box {
		box-shadow: 0rpx 13rpx 57rpx 0rpx rgba(8, 73, 162, 0.11);
		background: #35bcff;
		border-radius: 10rpx;
	}

	.d-list-box1 {
		box-shadow: 0rpx 13rpx 57rpx 0rpx rgba(8, 73, 162, 0.11);
		background: rgb(48, 182, 134);
		border-radius: 10rpx;
	}

	.d-list-box2 {
		box-shadow: 0rpx 13rpx 57rpx 0rpx rgba(8, 73, 162, 0.11);
		background: rgb(253, 168, 92);
		border-radius: 10rpx;
	}

	.d-tag {
		background: #f3f3f3;
		border-radius: 4rpx;
		height: 36rpx;
		font-size: 24rpx;
		font-weight: 500;
		color: #333333;
		padding: 0 18rpx;
	}

	.d-be {
		color: #bebebe;
	}

	.d-red {
		color: #ffffff;
		margin-top: 10rpx !important;
	}

	.d-white {
		color: #ffffff;
		margin-top: 10rpx !important;
	}

	.d-xuxian {
		width: 100%;
		height: 1rpx;
		border-bottom: 1px dashed white;
		margin-top: 10rpx;
	}

	.d-bold {
		font-weight: bold;

	}

	.goods-settle-accounts {
		height: 96upx;
		position: fixed;
		bottom: 0;
		z-index: 99;
		width: 100%;
		background-color: #f0f0f0;
		display: flex;
		align-items: center;
		justify-content: space-between;

		.left {
			display: flex;
			align-items: center;
			padding-left: 10upx;

			.select {
				width: 40upx;
				// margin-right: $spacing-sm;
			}
		}

		.right {
			display: flex;
			align-items: center;

			.goods-price-total {
				font-size: 26rpx;
			}

			.goods-price-total text:nth-child(2) {
				font-size: 30rpx;
				padding-top: 4upx;
				margin-left: 8upx;
				color: rgb(253, 110, 76);
			}

			.goods-count-btn {
				font-size: 28upx;
				width: 180upx;
				background-color: #35c3ff;
				color: #fff;
				height: 100upx;
				text-align: center;
				line-height: 100upx;
				margin-left: 20upx;
			}

			.goods-enshrine {
				// color: $base-color;
				padding: 5upx 20upx;
				// border: 1upx solid $base-color;
				border-radius: 30upx;
				margin-right: 30upx;
			}

			.goods-delete {
				padding: 5upx 20upx;
				color: #FD6E4C;
				border: 1px solid #FD6E4C;
				border-radius: 30upx;
				margin-right: 20rpx;
			}
		}
	}
</style>